package com.itmk.web.user_menu.service.serviceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itmk.web.user_menu.entity.AssignParm;
import com.itmk.web.user_menu.entity.UserMenu;
import com.itmk.web.user_menu.mapper.UserMenuMapper;
import com.itmk.web.user_menu.service.UserMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 山顶洞人郑某
 * @className UserMenuServiceImpl.java
 * @date 2023 12 06
 */
@Service
public class UserMenuServiceImpl extends ServiceImpl<UserMenuMapper, UserMenu> implements UserMenuService {
    @Autowired
    UserMenuMapper userMenuMapper;

    @Override
    @Transactional  //保证原子性
    public void saveParm(AssignParm parm) {
        //先删除 再插入
        LambdaQueryWrapper<UserMenu>  queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserMenu::getUserId,parm.getAssId());
        userMenuMapper.delete(queryWrapper);
        userMenuMapper.saveMenu(parm.getAssId(),parm.getList());
    }
}
